<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<h1>新增核酸记录</h1>
<form method="post" action="/medicalAssay">
    <table border="1px">
        <tr>
            <td colspan="2">添加核酸检查信息</td>
        </tr>
        <tr>
            <td>被检查人姓名</td>
            <td>
                <input type="text" name="assayUser">
            </td>
        </tr>
        <tr>
            <td>被检查人手机号</td>
            <td>
                <input type="text" name="phone">
            </td>
        </tr>
        <tr>
            <td>被检查人身份证</td>
            <td>
                <input type="text" name="cardNum">
            </td>
        </tr>
        <tr>
            <td>检测机构</td>
            <td>
                <select name="hospitalId" id="sel">
                    <option value="">-请选择-</option>
                </select>
            </td>
        </tr>
        <tr>
            <td>检测日期</td>
            <td>
                <input type="text" name="assayTime">
            </td>
        </tr>
        <tr>
            <td colspan="2">
                <button type="submit">添加</button>
            </td>
        </tr>
    </table>
</form>
</body>
<script src="/webjars/jquery/3.4.1/jquery.js"></script>

<script>
    // window.location.href="/medicalAssay/index"
    $(function () {
        //请求后台拿到数据
        $.ajax({
            url:"/hospital",
            method:"get",
            dataType:"json",
            success:function (data) {
                console.log(data);
                var option = "<option value=\"\">-请选择机构-</option>";
                for (let i = 0; i < data.length; i++) {
                    option += "<option value=\""+data[i].id+"\">"+data[i].name+"</option>"
                }
                $("#sel").html(option);
            }
        })
    })
</script>

</html>